import ajaxAsync from 'vue-xiaobu-utils'

let test = false

let testTime = 0
/**
 * 获取账单列表
 * @param {Number} pageIndex 页码
 * @param {Number} pageSize 页长度
 */
function getConsumeList(pageIndex = 1, pageSize = 10) {
  if (test) {
    testTime++
    return new Promise((resolve, reject) => {
      let detailList = []
      let state = 1
      for (let i = 0; i < 6; i++) {
        if (i > 2) {
          state = 3
        }
        let type = ((i + testTime) % 2) + state
        let detail = {
          TRADE_NO: '123456' + i,
          TITLE: '随便打点字',
          TRADE_TIME: '2019-02-2' + testTime,
          TX_AMOUNT: 2.0 + testTime,
          IS_REFUND_SUCCESS: i % 2,
          TRADE_SCENE: type,
          TRADE_STATUS: (i % 5) + 1
        }
        if ((i + 1) % 10 === 0) {
          detail.TRADE_STATUS = 9
        }
        switch (type) {
          case 1:
            detail.TITLE = '钱包余额-充值'
            break
          case 2:
            detail.TITLE = '钱包余额-提现'
            break
          case 3:
            detail.TITLE = '乘坐公交'
            break
          case 4:
            detail.TITLE = '退款-乘坐公交'
            break
        }
        detail.TITLE = detail.TITLE + testTime
        detailList.push(detail)
      }
      let monthItem = {
        MONTH: '2018-09',
        BILL_AMOUNT: 5,
        REFUND_AMOUNT: 2,
        TRADE_DETAILS: detailList
      }
      let body = {
        COUNT: 5,
        LIST: [monthItem]
      }
      console.log(JSON.stringify(body))
      resolve(body)
    })
  } else {
    let sendData = {
      // CARD_NO: '6203983617', // fyy
      // CARD_NO: '1256948602', // zff
      // CARD_NO: '2854363213', // jyy
      // CARD_NO: '4206525774', // jyy-ygk
      // CARD_NO: '3655817712', // jyy-ygk
      PAGE_INDEX: pageIndex,
      PAGE_CAPACITY: pageSize
    }
    // getCardList().then(() => {})
    // ajaxAsync('/vcard/app_recharge/detail', {
    //   OUT_TRADE_NO: '2018122716253571130'
    // }).then(() => {})
    return ajaxAsync('/trade/bill/list', sendData)
  }
}

/**
 * 获取失败行程数
 */
function getPosBillUnpayCount() {
  return ajaxAsync('/posbill/unpaysuccess/count', {})
}
export { getConsumeList, getPosBillUnpayCount }
